<?php
namespace Admin\Controller;

use Think\Controller;

class InformController extends Controller
{

    public function index()
    {
        sess();
        $data['url'] = $_SERVER["PATH_INFO"];
        if (in_array($data, control())) {
            $this->error('你没有权限！');
        }
        $cust = M('Info');
        $map = _search('Info');
        $map['juid'] = array(
            'like',
            '%' . session('uid') . '%'
        );
        $count = $cust->where($map)->count();
        $Page = getpage($count, 5); // 实例化分页类 传入总记录数
        $show = $Page->show(); // 分页显示输出
        $list = $cust->where($map)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        $this->assign('list', $list);
        $this->assign('page', $show);
        updateTime();
        $this->display();
    }

    public function outxls()
    {
        sess();
        $data['url'] = $_SERVER["PATH_INFO"];
        if (in_array($data, control())) {
            $this->error('你没有权限！');
        }
        $model = M('Info');
        $map = _search("Info");
        $map['juid'] = array(
            'like',
            '%' . session('uid') . '%'
        );
        $list = $model->where($map)
            ->field('id,juname,title,jzrq,uname,addtime,uuname,updatetime')
            ->select();
        $headArr = array(
            'ID',
            '接收人',
            '通知标题',
            '截止日期',
            '发布人',
            '发布时间',
            '最后回复',
            '回复时间'
        );
        $filename = '通知公告';
        xlsout($filename, $headArr, $list);
        updateTime();
    }

    public function add()
    {
        sess();
        $data['url'] = $_SERVER["PATH_INFO"];
        if (in_array($data, control())) {
            $this->error('你没有权限！');
        }
        if (IS_POST) {
            if (add("Info")) {
                $this->assign('zt','发布成功！');
            } else {
                $this->assign('zt','发布失败！');
            }
        }
        updateTime();
        $this->display();
    }

    public function edit()
    {
        sess();
        $data['url'] = $_SERVER["PATH_INFO"];
        if (in_array($data, control())) {
            $this->error('你没有权限！');
        }
        $model = M('Info');
        $Rs = $model->getById(I('get.id'));
        $this->assign('Rs', $Rs);
        if (IS_POST) {
            if (edit("Info")) {
                $this->assign('zt','编辑成功！');
            } else {
                $this->assign('zt','编辑失败！');
            }
        }
        updateTime();
        $this->display();
    }
    
    // 删除功能为此通知不显示
    public function del()
    {
        sess();
        $data['url'] = $_SERVER["PATH_INFO"];
        if (in_array($data, control())) {
            $this->error('你没有权限！');
        }
        $model = M('Info');
        $data['id'] = I('get.id');
        $data['juid'] = 0;
        $d = $model->save($data);
        if ($d) {
            $this->assign('zt','删除成功！');
        } else {
            $this->assign('zt','删除失败！');
        }
        updateTime();
        $this->display('Inform/index');
        redirect(U('Inform/index'),1);
    }
}